from django.db import models
from apps.courses.models import Course
from apps.teachers.models import Teacher


# 定义班级模型类
class Class(models.Model):
    SCHOOLTIME_CHOICES = (
        (0, '每周一三五 20:00 ~ 22:00'),
        (1, '每周二四六 20:00 ~ 22:00'),
    )
    TEACHMETHOD_CHOICES = (
        (0, '直播'),
        (1, '录播'),
    )
    STATE_CHOICES = (
        (0, '待开班'),
        (1, '已开班'),
        (2, '已结课'),
    )
    stage_no = models.CharField(max_length=10, verbose_name='班期')
    course = models.ForeignKey(Course, on_delete=models.PROTECT, related_name='course_classes', verbose_name='课程')
    speaker = models.ForeignKey(Teacher, on_delete=models.PROTECT, related_name='speaker_classes', verbose_name='主讲老师')
    head = models.ForeignKey(Teacher, on_delete=models.PROTECT, related_name='head_classes', verbose_name='班主任')
    start_date = models.DateField(verbose_name="开班时间")
    schooltime = models.SmallIntegerField(choices=SCHOOLTIME_CHOICES, default=0, verbose_name='授课时间')
    teach_method = models.SmallIntegerField(choices=TEACHMETHOD_CHOICES, default=0, verbose_name='授课方式')
    state = models.SmallIntegerField(choices=STATE_CHOICES, default=1, verbose_name='班级状态')
    data_link = models.CharField(max_length=100, null=True, blank=True, verbose_name='班级资料连接')
    remark = models.CharField(max_length=50, null=True, blank=True, verbose_name='班级信息备注')

    class Meta:
        # 指明数据库表名
        db_table = 'tb_class'
        # 在admin站点中显示的名称
        verbose_name = '班级表'
        # 显示的复数名称
        verbose_name_plural = verbose_name
        # 定义联合唯一字段
        unique_together = ['stage_no', 'course']

    def __str__(self):
        """定义每个数据对象的显示信息"""
        return f"{self.stage_no}-{self.course.name}"

